﻿@namespace AntDesign
@inherits AntDomComponentBase

@if (_hasClosed)
{
    return;
}

@if (IsTab)
{
    var ondragoverPreventDefault = _isActive;
    var onclickStopPropagation = !_isActive;

    <div @key="Key"
         @ref="_tabRef"
         @onclick:stopPropagation="@onclickStopPropagation"
         @onclick="@(e => Parent.HandleTabClick(this))"
         @ondragover:preventDefault="@ondragoverPreventDefault"
         @ondragstart="@(e => Parent.HandleDragStart(e, this))"
         @ondrop="@(_ => Parent.HandleDrop(this))"
         aria-controls="@($"rc-tabs-{Id}-tab-{Key}")"
         aria-selected="@(_isActive)"
         class="@ClassMapper.Class"
         draggable="@Parent.Draggable.ToString()"
         id="@($"rc-tabs-{Id}-tab-{Key}")"
         ondragover="event.preventDefault();">
        <div role="tab" aria-selected="false" class="ant-tabs-tab-btn" tabindex="0">
            @if (TabTemplate != null)
            {
                @TabTemplate
            }
            else
            {
                @Tab
            }
        </div>
        @if (Parent.Type == TabType.EditableCard && Closable)
        {
            <button type="button" aria-label="remove" tabindex="0" class="ant-tabs-tab-remove" @onclick="(e) => Parent.RemoveTab(this)" @onclick:stopPropagation>
                <Icon Type="close" />
            </button>
        }
    </div>
}
else if (IsPane)
{
    <div @key="Key"
         tabindex="@(_isActive ? "0" : "-1")"
         class="ant-tabs-tabpane @(_isActive ? "ant-tabs-tabpane-active" : "")"
         id="@($"rc-tabs-{Id}-panel-{Key}")"
         role="tabpanel" aria-hidden="@(_isActive ? "false" : "true")"
         aria-labelledby="@($"rc-tabs-{Id}-panel-{Key}")"
         style="@(_isActive || Parent.Animated ? "" : "display: none;")">
        @if (_isActive || _hasRendered || ForceRender)
        {
            _hasRendered = true;
            @ChildContent
        }
    </div>
}